/* 
 * File:   TimerEvent.h
 * Author: Julian Sanin
 *
 * Created on 01/03/2014, 15:18
 * Ported mbed ticker api to PIC24.
 * Sources: us_ticker_api.h,
 *          us_ticker_api.c,
 *          TimerEvent.h,
 *          TimerEvent.cpp
 */

/* mbed Microcontroller Library
 * Copyright (c) 2006-2013 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef TIMEREVENT_H
#define	TIMEREVENT_H

#ifdef	__cplusplus
extern "C" {
#endif

#include "Object.h"

struct TimerEvent_t;

struct TickerEvent_t {
    struct TimerEvent_t *id;
    unsigned int timestamp;
    struct TickerEvent_t *next;
};

/**
 * Abstract timer interrupts.
 * Timer1 module is being used to dispatch events.
 */
CLASS_EXTEND(TimerEvent, Object)
    struct TickerEvent_t _event;
OVERRIDE(TimerEvent, Object)
    void (*dtor)(TimerEvent *);
    /** The handler to be serviced in the derived class. */
    void (*onEvent)(TimerEvent *);
METHODS
    void _TimerEvent_ctor(TimerEvent *obj);
    void _TimerEvent_dtor(TimerEvent *obj);
    /**
     * @brief Adds the TimerEvent to the event list.
     * @param[in]  obj       The TimerEvent to be added.
     * @param[in]  timestamp The desired time when onEvent() should be called.
     */
    void _TimerEvent_insert(TimerEvent *obj, unsigned int timestamp);
    /**
     * @brief Removes the TimerEvent from the event list.
     * @param[in]  obj The TimerEvent to be removed.
     */
    void _TimerEvent_remove(TimerEvent *obj);
    /**
     * @brief Interrupt handler to dispatch the registered event.
     * @param[in]  id The TimerEvent to be dispatched.
     */
    void _TimerEvent_interrupt(TimerEvent *id);
CLASS_END

#ifdef	__cplusplus
}
#endif

#endif	/* TIMEREVENT_H */
